/**
 * 自动调整高度 
 */
function autoHeight(objid,offset)
{
	try{
		$('#'+objid).height(($(window).height()-offset));
	}catch(e){
		
	}
}

function doSubmit(id,action)
{
	$('#'+id).attr('action',action);
	$('#'+id).attr('target','_self');
	//$('#'+id).submit();
	$.ajax({
        type:"post",
        dataType:"json",
        url:action,
        data:$("#"+id).serialize(),
        beforeSend:function(obj){
            //$this.attr("disabled","disabled");
        },
        success:function(data){
            if(data.code==1){
                layer.msg(data.msg);
                setTimeout(function() { 
		            window.location.href=data.url;
		        },1000);
            }else{
                layer.msg(data.msg);
            }  
        }
    });
}

/**
 * 全选/反选
 */
$(function(){
   $("#checkAll").click(function() {
        $('input[la="checkbox"]').attr("checked",this.checked); 
    });
});

function isCheckboxChecked()
{
	var re=false;
	$('input[la="checkbox"]').each(function(){
	   if($(this).attr('checked'))
	   {
		   re=true;
		   return true;
	   }
	});
	return re;
}

//删除操作，删除数据后刷新页面
if ($('a.js-ajax-delete').length) {
    $('.js-ajax-delete').on('click', function (e) {
        e.preventDefault();
        var $_this = this,
            $this = $($_this),
            href = $this.data('href'),
            msg = $this.data('msg');
		href = href?href:$this.attr('href');
		msg  = msg?msg:'确定删除此菜单?';
        if(confirm(msg)){
		    $.getJSON(href).done(function (data) {
                if(data.code == 1){
                    if(data.url){
                    	layer.msg(data.msg);
                        setTimeout(function() { 
				            window.location.href=data.url;
				        },1000);
                    }else{
                        reloadPage(window);
                    }
                }else{
                    layer.msg(data.msg);
                }
            });
        }
    });
}
